/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.GroupMembership;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest;
/*     */ import com.zimbra.soap.admin.type.DistributionListSelector;
/*     */ import com.zimbra.soap.admin.type.DistributionListSelector.DistributionListBy;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAdminConsoleUIComp
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  46 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  54 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  59 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  60 */     Provisioning prov = Provisioning.getInstance();
/*  61 */     GetAdminConsoleUICompRequest req = (GetAdminConsoleUICompRequest)JaxbUtil.elementToJaxb(request);
/*  62 */     AccountSelector accountSel = req.getAccount();
/*  63 */     DistributionListSelector dlSel = req.getDl();
/*     */     
/*  65 */     Element resp = zsc.createElement(AdminConstants.GET_ADMIN_CONSOLE_UI_COMP_RESPONSE);
/*     */     
/*  67 */     if ((null != accountSel) && (null != dlSel)) {
/*  68 */       throw ServiceException.INVALID_REQUEST("can only specify eith account or dl", null);
/*     */     }
/*     */     
/*  71 */     Account authedAcct = getAuthenticatedAccount(zsc);
/*     */     
/*  73 */     Set<String> added = new HashSet();
/*  74 */     Provisioning.GroupMembership aclGroups = null;
/*     */     
/*  76 */     if (accountSel != null) {
/*  77 */       Key.AccountBy by = accountSel.getBy().toKeyAccountBy();
/*  78 */       String key = accountSel.getKey();
/*  79 */       Account acct = prov.get(by, key);
/*  80 */       AdminDocumentHandler.AccountHarvestingCheckerUsingCheckRight checker = new AdminDocumentHandler.AccountHarvestingCheckerUsingCheckRight(this, zsc, context, Rights.Admin.R_viewAccountAdminUI);
/*     */       
/*  82 */       if (acct == null) {
/*  83 */         defendAgainstAccountHarvestingWhenAbsent(by, key, zsc, checker);
/*     */       } else {
/*  85 */         if (!authedAcct.getId().equals(acct.getId())) {
/*  86 */           defendAgainstAccountHarvesting(acct, by, key, zsc, checker);
/*     */         }
/*  88 */         addValues(acct, resp, added, false);
/*  89 */         aclGroups = prov.getGroupMembership(acct, true);
/*     */       }
/*  91 */     } else if (dlSel != null) {
/*  92 */       Key.DistributionListBy by = dlSel.getBy().toKeyDistributionListBy();
/*  93 */       String key = dlSel.getKey();
/*  94 */       DistributionList dl = prov.getDLBasic(by, key);
/*  95 */       AdminDocumentHandler.GroupHarvestingCheckerUsingCheckRight checker = new AdminDocumentHandler.GroupHarvestingCheckerUsingCheckRight(this, zsc, context, Rights.Admin.R_viewDistributionListAdminUI);
/*     */       
/*     */ 
/*  98 */       if (dl == null) {
/*  99 */         defendAgainstGroupHarvestingWhenAbsent(by, key, zsc, checker);
/*     */       } else {
/* 101 */         defendAgainstGroupHarvesting(dl, by, key, zsc, checker);
/* 102 */         addValues(dl, resp, added, false);
/* 103 */         aclGroups = prov.getGroupMembership(dl, true);
/*     */       }
/*     */     }
/*     */     else {
/* 107 */       addValues(authedAcct, resp, added, false);
/* 108 */       aclGroups = prov.getGroupMembership(authedAcct, true);
/*     */     }
/*     */     
/* 111 */     if (aclGroups != null) {
/* 112 */       for (String groupId : aclGroups.groupIds()) {
/* 113 */         DistributionList dl = prov.get(Key.DistributionListBy.id, groupId);
/* 114 */         addValues(dl, resp, added, true);
/*     */       }
/*     */     }
/*     */     
/* 118 */     return resp;
/*     */   }
/*     */   
/*     */   private void addValues(NamedEntry entry, Element resp, Set<String> added, boolean inherited) {
/* 122 */     Set<String> values = entry.getMultiAttrSet("zimbraAdminConsoleUIComponents");
/* 123 */     for (String value : values) {
/* 124 */       if (!added.contains(value)) {
/* 125 */         resp.addNonUniqueElement("a").setText(value).addAttribute("inherited", inherited);
/*     */         
/* 127 */         added.add(value);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 134 */     relatedRights.add(Rights.Admin.R_viewAccountAdminUI);
/* 135 */     relatedRights.add(Rights.Admin.R_viewDistributionListAdminUI);
/*     */     
/* 137 */     notes.add("If account/dl is not specified, Do not need any right, all admins are allowed.");
/* 138 */     notes.add("If an account is specified, need the " + Rights.Admin.R_viewAccountAdminUI.getName() + " right.");
/*     */     
/* 140 */     notes.add("If a dl is specified, need the " + Rights.Admin.R_viewDistributionListAdminUI.getName() + " right.");
/*     */     
/* 142 */     notes.add("Note, this call does not check for the get attr right for zimbraAdminConsoleUIComponents attribute on the account/dl, nor on the admin groups they belong.  It simply checks the " + Rights.Admin.R_viewAccountAdminUI.getName() + " or " + Rights.Admin.R_viewDistributionListAdminUI.getName() + " right.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAdminConsoleUIComp.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */